import 'package:flutter_riverpod/flutter_riverpod.dart';

class UserState {
  String token;
  String nick_name;
  String account;
  int points;
  UserState({
    required this.token,
    required this.account,
    required this.nick_name,
    required this.points,
  });
  UserState copyWith({
    String? token,
    String? nickName,
    String? account,
    int? points,
  }) {
    return UserState(
      token: token ?? this.token,
      nick_name: nickName ?? this.nick_name,
      account: account ?? this.account,
      points: points ?? this.points,
    );
  }
}

class UserNotifier extends StateNotifier<UserState> {
  UserNotifier()
    : super(UserState(token: "123", account: "", nick_name: "", points: 0));

  void updateToken(String newToken) {
    state = state.copyWith(token: newToken); // 关键: 创建新状态对象
  }

  void updateProfile(String nickName, int points) {
    state = state.copyWith(nickName: nickName, points: points);
  }
}

final userProvider = StateNotifierProvider<UserNotifier, UserState>((ref) {
  return UserNotifier();
});
